package com.tzeng.hist.activity;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tzeng.hist.R;
import com.tzeng.hist.manager.TitleManager;

public class NewsDetailActivity extends BaseActivity {
	private WebView mWebview;
	private WebSettings settings; 

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_news_detail);
		initView();
		// 初始化导航栏
		TitleManager.showTitle(this, new int[]{1}, R.string.app_name);
	}

	@SuppressLint("SetJavaScriptEnabled")
	void initView() {
		mWebview = (WebView) findViewById(R.id.news_content);
		settings = mWebview.getSettings();
		settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		settings.setJavaScriptEnabled(true);
		settings.setJavaScriptEnabled(true);
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		// 设置webview缓存
		settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
		mWebview.loadUrl("file:///android_asset/news.html");
		mWebview.setWebViewClient(new MyWebViewClient());

	}

	private class MyWebViewClient extends WebViewClient {
		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			super.onPageStarted(view, url, favicon);
		}

		@Override
		public void onPageFinished(WebView view, String url) { 
			super.onPageFinished(view, url);
		}

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			if (url.indexOf("tel:") < 0) {// 页面上有数字会导致连接电话
				view.loadUrl(url);
			}
			return true;
		}
	}

}
